<?php


namespace App\Http\Controllers\Api;
use App\Http\Controllers\BaseController;
use App\Models\Address;
use App\Models\Balance;
use App\Models\User;
use Illuminate\Http\Request;

class TeamController extends BaseController
{
    public $model = Address::class;


    /**
     * 列表
     * @param Request $request
     * @return mixed
     */
    public function index(Request $request) {
        $user_id = $this->getUserId();
        $users = User::where('rec_merchant_id', $user_id)->select(['id', 'nickname', 'avatar_url', 'created_at'])->paginate(per_page());
        foreach ($users as $item) {
            $all = [
                Balance::TYPE_VIP,
                Balance::TYPE_MALL
            ];
            $total_amount = Balance::where('merchant_id', $item->id)->whereIn('type', $all)->sum('amount');
            $item->total_commission_yuan = format_yuan($total_amount);
        }
        return $this->paginate($users);
    }




}

